﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SalaryChannel.SCQueryService;

namespace SalaryChannel
{
    public partial class QueryLog : UserControl
    {
        public QueryLog()
        {
            InitializeComponent();

            ServiceInstance.QueryClient.GetQueryLogTableCompleted += new EventHandler<GetQueryLogTableCompletedEventArgs>(dclient_GetQueryLogTableCompleted);

        }

       

        void dclient_GetQueryLogTableCompleted(object sender, GetQueryLogTableCompletedEventArgs e)
        {
            try
            {
                this.ResultGrid.ItemsSource = e.Result;
                if (e.Result.Count == 0)
                {
                    App.MessageBox.ShowDialog("查询不到数据", Title.Error);
                }
            }
            catch 
            {

                App.MessageBox.ShowDialog("获取统计结果失败", Title.Error);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }

        }

        void dclient_GetStatisMonCompleted(object sender, GetStatisMonCompletedEventArgs e)
        {try
            {
                if (e.Result == null)
                {
                    App.MessageBox.ShowDialog("获取统计月份失败", Title.Error);
                }
                else
                {
                    this.StatisCBox.ItemsSource = e.Result;
                    this.StatisCBox.SelectedIndex = StatisCBox.Items.Count-1;
                }

            }
            catch
            {
                App.MessageBox.ShowDialog("获取统计月份失败", Title.Error);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
                //this.QueryBtn.IsEnabled = true;
            }
        }

        private void StatisCBox_DropDownOpened(object sender, EventArgs e)
        {
           
        }

        private void QueryBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.StatisCBox.SelectedItem != null)
                {
                    string mon = this.StatisCBox.SelectedItem.ToString();

                    if (string.IsNullOrEmpty(mon))
                    {
                        return;
                    }


                   
                    ServiceInstance.QueryClient.GetQueryLogTableAsync(mon);
                    // ServiceInstance.QueryClient.GetSalaryPoolAsync(App.CurrentUser, this.StatisCBox.SelectedItem.ToString(), this.ChannelIDTB.Text);

                    this.Cursor = Cursors.Wait;
                }
                else
                {
                    App.MessageBox.ShowDialog("请先选择查询月份！");
                }
            }
            catch 
            {
                App.MessageBox.ShowDialog(Properties.Resource.ConnectServerFailed, Title.Error);
            }
        }

        private void GetStatisMonBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                try
                {
                    ServiceInstance.QueryClient.GetStatisMonCompleted -= dclient_GetStatisMonCompleted;
                }
                catch 
                {
                   
                }
                ServiceInstance.QueryClient.GetStatisMonCompleted += new EventHandler<GetStatisMonCompletedEventArgs>(dclient_GetStatisMonCompleted);
                ServiceInstance.QueryClient.GetStatisMonAsync();
                this.Cursor = Cursors.Wait;
            }
            catch 
            {
                this.Cursor = Cursors.Arrow;
                App.MessageBox.ShowDialog(Properties.Resource.ConnectServerFailed, Title.Error);
            }
        }
    }
}
